namespace Mytodotodaylist.Core.Container
{
    using System;
    using Castle.Windsor;

    public static class IoC
    {
        private static readonly IWindsorContainer _container;
        
        static IoC()
        {
            _container = new WindsorContainer();
        }
        
        public static T Resolve<T>() where T : class
        {
            if (typeof(T).Equals(typeof(IWindsorContainer)))
            {
                return new WindsorContainer() as T;
            }
            return _container.Resolve<T>();
        }
        
        internal static void AddComponent(string key, Type serviceType, Type classType)
        {
            _container.AddComponent(key, serviceType, classType);
        }
        
        internal static void AddComponentInstance<T>(object instance)
        {
            _container.Kernel.AddComponentInstance<T>(instance);
        }
    }
}